// ==UserScript==
// @name         贴吧签到
// @namespace    http://zerowuchina.oschina.io/base/
// @version      0.0.11
// @icon         http://www.baidu.com/favicon.ico
// @description  贴吧签到
// @author       Zero Wu
// @match        *://tieba.baidu.com/*
// @updateURL    https://gitee.com/zerowuchina/base/raw/master/js/tiebaAutoClick.meta.js
// @downloadURL  https://gitee.com/zerowuchina/base/raw/master/js/tiebaAutoClick.user.js
// @grant        none
// @run-at       document-end
// ==/UserScript==
function pathname() {
    return window.location.pathname;
}
function newTime(day,h, m, s) {
	var d = new Date();
    d.setDate(d.getDate() + day);
    d.setHours(h);
    d.setMinutes(m);
    d.setSeconds(s);
    console.log(d.toLocaleString());
    return d;
}
console.log(pathname());
$(document).ready(function(){
    if(pathname() === "/index.html") {
        if(jQuery.cookie('isSigned') !== "true") {
            if ((new Date()).getHours() >= 1) {

                var f = setInterval(function(){
                    console.log($('.onekey_btn')[0]);
                    if($('.onekey_btn').length > 0) {
                        //console.log($('.onekey_btn').click());
                        $('.onekey_btn').click();
                        //console.log($('.sign_btn').length);
                        if($('.sign_btn').length > 0) {
                            if ($('.sign_btn').text() === '签到成功') {
                                console.log($('.sign_btn').text());
                                $('.dialogJclose').click();
                                console.log("关闭对话框");
                                jQuery.cookie('isSigned','true',{expires:newTime(1,1,0,0)});
                                clearInterval(f);
                            } else {
                                $('.sign_btn').click();
                                console.log("点击自动签到");
                            }
                        }
                    }
                },500);
            } else {
                console.log("时间还没到");
            }
        } else {
            console.log("自动签到过了");
        }
    } else if(pathname() === "/f") {
        var flag = setInterval(function(){
            var a = $('#signstar_wrapper>a');
            if(a.length > 0) {
                console.log(a.attr('title'));
                if(a.attr('title') === "签到完成") {
                    console.log("单独签到");
                    clearInterval(flag);
                } else  {
                    a.click();
                }
            }
        },500);
    }
});
